route.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { ApiPath } from "@/app/constant";
  2. import { NextRequest, NextResponse } from "next/server";
  3. import { handle as openaiHandler } from "../../openai";
  4. import { handle as azureHandler } from "../../azure";
  5. import { handle as baiduHandler } from "../../baidu";
  6. import { handle as bytedanceHandler } from "../../bytedance";
  7. import { handle as alibabaHandler } from "../../alibaba";
  8. import { handle as iflytekHandler } from "../../iflytek";
  9. async function handle(
  10. req: NextRequest,
  11. { params }: { params: { provider: string; path: string[] } },
  12. ) {
  13. const apiPath = `/api/${params.provider}`;
  14. console.log(`[${params.provider} Route] params `, params);
  15. switch (apiPath) {
  16. case ApiPath.Azure:
  17. return azureHandler(req, { params });
  18. case ApiPath.Baidu:
  19. return baiduHandler(req, { params });
  20. case ApiPath.ByteDance:
  21. return bytedanceHandler(req, { params });
  22. case ApiPath.Alibaba:
  23. return alibabaHandler(req, { params });
  24. // case ApiPath.Tencent: using "/api/tencent"
  25. case ApiPath.Iflytek:
  26. return iflytekHandler(req, { params });
  27. default:
  28. return openaiHandler(req, { params });
  29. }
  30. }
  31. export const GET = handle;
  32. export const POST = handle;
  33. export const runtime = "edge";
  34. export const preferredRegion = [
  35. "arn1",
  36. "bom1",
  37. "cdg1",
  38. "cle1",
  39. "cpt1",
  40. "dub1",
  41. "fra1",
  42. "gru1",
  43. "hnd1",
  44. "iad1",
  45. "icn1",
  46. "kix1",
  47. "lhr1",
  48. "pdx1",
  49. "sfo1",
  50. "sin1",
  51. "syd1",
  52. ];